package com.itheima.tlias.controller;

import com.itheima.tlias.annotation.Log;
import com.itheima.tlias.common.result.Result;
import com.itheima.tlias.pojo.po.InsertStudentParam;
import com.itheima.tlias.pojo.po.SelectStudentPageParam;
import com.itheima.tlias.pojo.po.UpdateStudentParam;
import com.itheima.tlias.service.StudentService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {

    @Resource
    private StudentService studentService;
    @Log
    @PostMapping
    public Result insertStudent(@RequestBody InsertStudentParam param){
        log.info("新增学员请求参数,{}",param);
        return studentService.insertStudent(param);
    }

    @GetMapping
    public Result selectStudentByPage(SelectStudentPageParam param){
        log.info("分页查询学员请求参数,{}",param);
        return studentService.selectStudentByPage(param);
    }
    @Log
    @PutMapping("/violation/{id}/{score}")
    public Result violation(
            @PathVariable("id") Integer id
            ,@PathVariable("score")
            @Pattern(regexp = "^\\d+$", message = "不能为空") String score){
        log.info("违纪处理参数请求，id,{}，score，{}",id,score);
        return studentService.violation(id ,Integer.valueOf(score));
    }
    @GetMapping("/{id}")
    public Result selectStudentById(@PathVariable("id")Integer id){
        log.info("根据学生ID查询请求参数，{}",id);

        return studentService.selectStudentById(id);

    }
    @Log
    @PutMapping
    public Result updateStudent(@RequestBody UpdateStudentParam param){
        log.info("更新学生请求参数，{}",param);
        return studentService.updateStudent(param);
    }
    @Log
    @DeleteMapping("/{ids}")
    public Result deleteStudentByIds(@NotNull @PathVariable("ids") List<Integer> ids){
        log.info("批量删除学生请求参数，{}",ids);
        return studentService.batchDeleteStudentByIds(ids);
    }
}
